home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / modula2 / 110 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.2 KB  |  55 lines

  1. Newsgroups: comp.lang.modula2
  2. Path: mcrcim.mcgill.edu!nyongwa!aliath
  3. From: aliath@nyongwa.montreal.qc.ca (Michel De Rosa)
  4. Subject: Re: Modula2 for C programmers?
  5. Message-ID: <DLIGLJ.FDE@nyongwa.montreal.qc.ca>
  6. Organization: Radio Free Nyongwa, Montreal (Qc), Canada
  7. Date: Sun, 21 Jan 1996 03:05:43 GMT
  8. References: <erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4dqusf$d7k@weck.brokersys.com>
  9. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  10.  
  11. jguthrie@brokersys.com wrote:
  12. : Eric Obermuhlner (erico@cnmat.berkeley.edu) wrote:
  13. : : Hi out there
  14. : : How do I do the ugly things that C programmers like so very much in Modula 2?
  15. : : Like getting a pointer to a var, pointer arithmetic, bit operations (shift, and, or, exor).
  16. : Well, I wound up doing that kind of stuff in assembly language.  I also
  17. : concluded that the insistence on abstraction above all else was sometimes 
  18. : detrimental to my efforts to easily write things such as CRC routines.
  19. Well there are a few reasons why we consider this sort of thing 'ugly'..
  20. Even so, there should be little need to go to asm for them..
  21.  
  22. Assigning a pointer to an ordinal variable, would be done thru type
  23. coercion, as in:   ordVar := CARDINAL(ptrVar);
  24.  
  25. THis assumes, of course, that the length (bit-size) of a CARDINAL is the
  26. same as for a pointer..
  27.  
  28. Pointer arith.. ugh!!! well if you *must*, coercing the pointer to a
  29. cardinal will often do the trick... but if you work on a platform with
  30. segmented addresses you'll have a lot of fun.. ISO helps, here by providing
  31. functions for incrementing and decrementing Adresses..
  32.  
  33. Bit operations.. unfortunately with pre-ISO compilers, we where usually
  34. stuck with multiplying or dividing by 2, for shift operations (rotate is
  35. a tad more involved), now ISO also provides functions for those.. for
  36. and/or/xor etc.. it's always been possible to do these, using the set
  37. operators.. first coerce to a BITSET, then apply these ops:
  38.  
  39.   +  ... set union,   'or'
  40.   *  ... set intersection,  'and'
  41.   /  ... set symmetric difference,  'xor'
  42.   -  ... set difference,  'and not'
  43.  
  44. Further you can more easily test for a bit, using:   bit IN someBitset
  45.  
  46. Set a specific bit:  INCL(someBitset, bitToSet)
  47. Reset a specific bit:  EXCL(someBitset, bitToReset)
  48.  
  49. Ciao!
  50. Michel De Rosa
  51. Aliath@nyongwa.montreal.qc.ca
  52.